#pragma once
#include <iostream>
#include <string>
#include <array>
#include <sstream>
#include <istream>
#include <fstream>
#include <iterator>
#include <vector>


using namespace std;

struct dataa
{
	long long sum;
	int n;
	dataa()
	{
		sum = 0;
		n = 0;
	}
};

class statistics
{
private:
	vector<dataa> v;


	int a;
	int c;
public:

	statistics(void)
	{
		for (int i = 0; i < 1000; i++)
		{
			v.push_back(dataa());
		}
	}



	void readfromfile()
	{
		ifstream fin;
		fin.open("salary.txt");

		if (!fin.good() )
		{
			cout << "Couldn't read file";
		}
		int i = 0;

		int range;
		while (!fin.eof() )
		{
			fin >> a;

			if ( a < 1000000)
			{
				v[a/1000].n++;
				v[a/1000].sum += a;
			}

		}


	}

	int calculate_mean()
	{
		int antal = 0;
		int i;
		long long summa = 0;
		int k;
		 

		for (i = 0; i < 1000; i++)
		{

			antal += v[i].n;
			summa += v[i].sum;
		}

		return summa/antal;
	}

	int percentile(int procent)
	{
		int antal = 0;
		int i;
		long long summa = 0;
		int k = 0;
		float procentcheck;

		procentcheck = procent/100.0;

		for (i = 0; i < 1000; i++)
		{
			antal += v[i].n;
		}

		for (i = 0; i < 1000; i++)
		{
			k = v[i].n;
			if (k > antal*procentcheck)
			{
				return i*1000;
			}
		}
	
					
	}

	void main1()
	{
		
		readfromfile();
		cout << calculate_mean() << endl;
		cout << percentile(50) << endl;
	}


	~statistics(void)
	{
	}
};

